package com.xiaotu.storage;

import java.util.Date;

import org.springframework.stereotype.Component;

import com.xiaotu.common.util.Constants;
import com.xiaotu.common.util.DataRedisKeyUtils;
import com.xiaotu.common.util.Constants.DataRedisKey;
import com.xiaotu.storage.converter.AConverter;
import com.xiaotu.storage.converter.ConverterFactory;
import com.xiaotu.storage.model.CacheDataModel;

import net.sf.json.JSONObject;

/**
 * @类名 TVWBStorageProcessor
 * @日期 2017年3月1日
 * @作者 高海军
 * @功能 作品微博转储
 */
@Component("TVWBStorageProcessor")
public class TVWBStorageProcessor extends AHSetStorageProcessor
{
	
	@Override
	public String process(JSONObject target, CacheDataModel cacheData,
			Date date)
	{
		this.validateData(target);
		return this.list2CSVLine(ConverterFactory.convert(target,
				this.getFields(),
				new String[] { AConverter.STRING_CONVERT,
						AConverter.STRING_CONVERT, AConverter.INTEGER_CONVERT,
						AConverter.INTEGER_CONVERT, AConverter.INTEGER_CONVERT,
						AConverter.INTEGER_CONVERT, AConverter.INTEGER_CONVERT,
						AConverter.STRING_CONVERT,
						AConverter.TIMESTAMP_CONVERT },
				new boolean[] { true, true, true, true, true, true, true, true,
						true }));
	}
	
	/**
	 * 数据校验
	 * @param target 转储数据
	 */
	protected void validateData(JSONObject target)
	{
		this.validateAllNotEmpty(target, "tvId", "tvName", "fans",
				"readFrequency", "commentFrequency", "weiboType");
	}
	
	/**
	 * 转储字段列表
	 * @return 字段列表
	 */
	protected String[] getFields()
	{
		return new String[] { "tvId", "tvName", "fans", "readFrequency",
				"commentFrequency", "weibo", "concern", "weiboType",
				"timestamp" };
	}
	
	@Override
	protected String getRedisKey(Date date)
	{
		return DataRedisKeyUtils.getKey(DataRedisKey.TV_Weibo_YYYYMMDD, date);
	}
	
	@Override
	public String getDataType()
	{
		return Constants.PageDataType.WEIBO;
	}
	
	@Override
	public String getTaskType()
	{
		return Constants.SpiderTaskType.WEIBO_TV;
	}
	
}
